﻿@using Web.Extensions;
@model Tuple<Project, IList<VacancyModel>, bool>
@{
    ViewBag.Title = "Проект " + Model.Item1.Name;
}
@section HEAD{
    <script src="@Url.Content("~/Content/js/application.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Content/js/jquery.fileupload-ui.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Content/js/jquery.fileupload.js")" type="text/javascript"></script>
    <link href="@Url.Content("~/Content/css/jquery.fileupload-ui.css")" rel="stylesheet" type="text/css" />
    <link href="@Url.Content("~/Content/js/jquery.fancybox/fancybox/jquery.fancybox-1.3.4.css")" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="@Url.Content("~/Content/js/jquery.fancybox/fancybox/jquery.fancybox-1.3.4.js")"></script>
    <style>
        form.file_upload input
        {
            position: absolute;
            top: 0;
            right: 37px;
            margin: 0;
            border: solid transparent;
            opacity: 0;
            -ms-filter: 'alpha(opacity=0)';
            filter: alpha(opacity=0); /*-o-transform: translate(-300px, -300px);
      -moz-transform: translate(-800px, 0);*/
            cursor: pointer;
            height: 100%;
        }
    </style>

    <meta property="og:title" content='GoodWorx-Проект: @Model.Item1.Name' />
    <meta property="og:type" content="activity"/>
    <meta property="og:url" content='@Url.ActionAbsolute("Project","View", Model.Item1.Id )'/>
    <meta property="og:image" content='@(Model.Item1.ProjectAvatar != null ? Model.Item1.ProjectAvatar.Small.OriginalSizeUrl : Url.Absolute("/Content/img/logo_medium.jpg").ToString())' />
    <meta property="og:site_name" content="GoodWorx"/>
    @*<meta property="fb:admins" content="USER_ID"/>*@
    <meta property="og:description" content='@Model.Item1.ShortDescription' />
}
<script type="text/javascript">
    $(document).ready(function () {
        $('#editBeginningDate_project_input').attachDatepicker({ maxDate: '+1m', minDate: '-1m' });
    });
</script>
<div id="main_inner">
    @if (Model.Item1.IsHidden)
    {
        <h1 class="warning">Проект скрыт. Сейчас он доступен только Вам. Чтобы открыть проект добавьте вакансии</h1>
    }
    @Html.Partial("EditVacancy", null, new ViewDataDictionary())
    <h3 class="editBeginningDate_field" id="beginningDate" name="editBeginningDate_field">
        <span id="BeginningDateContainer">
            @Html.Action("BeginningDate", new { id = @Model.Item1.Id })
        </span><a href="#" rel="editBeginningDate" class="editButton_edit editButton">Редактировать</a>
    </h3>
    <form action="@Url.Action("ChangeBeginningDate")" method="post" class="ajaxForm_noReload" name="editBeginningDate_form">
    <input type="hidden" name="id" value="@(Model.Item1.Id)"/>
    <input type="text" name="BeginningDate" class="editionInput editBeginningDate_input0 editBeginningDate_input"
        id="editBeginningDate_project_input" readonly="readonly" />
    <select name="BeginningTimeHour" class="editionInput editBeginningDate_input1 editBeginningDate_input">
        @for (int i = 0; i < 24; i++)
        {
            <option value="@i">@i</option>
        }
    </select>
    <select name="BeginningTimeMinute" class="editionInput editBeginningDate_input2 editBeginningDate_input">
        <option value="00">00</option>
        <option value="05">05</option>
        <option value="10">10</option>
        <option value="15">15</option>
        <option value="20">20</option>
        <option value="25">25</option>
        <option value="30">30</option>
        <option value="35">35</option>
        <option value="40">40</option>
        <option value="45">45</option>
        <option value="50">50</option>
        <option value="55">55</option>
    </select>
    <br class="editionInput" />
    <input type="submit" class="editionInput editBeginningDate_input" value="Сохранить" name="editBeginningDate"
            onClick="submitAndUpdate('editBeginningDate', 'BeginningDateContainer', '@(Url.Action("BeginningDate", new { id = @Model.Item1.Id }))'); return false;"/>
    <input type="reset" class="editButton_cancel editionInput editBeginningDate_input"
        value="Отмена" name="editBeginningDate" />
    </form>
    <h1 class="editNameText_field" id="pageHeader" name="editNameText_field">
        <span class="editNameText_field0">
            @(Model.Item1.Name)
        </span><a href="#" rel="editNameText" class="editButton_edit editButton">Редактировать</a>
    </h1>
    <form action="@Url.Action("ChangeName")" method="post" class="ajaxForm_noReload" name="editNameText_form">
    <input type="hidden" name="id" value="@(Model.Item1.Id)"/>
    <input type="text" name="editNameText_input" 
            class="editionInput editNameText_input0 editNameText_input" 
            id="editNameText_input" value="@(Model.Item1.Name)" 
            placeholder="Накормить бездомных"
            maxlength="100"/>
    <br class="editionInput" />
    <input type="submit" class="editButton_submit editionInput editNameText_input" value="Сохранить"
        name="editNameText" />
    <input type="reset" class="editButton_cancel editionInput editNameText_input" value="Отмена"
        name="editNameText" />
    </form>
    <div id="project_rightCol">
        @Html.Action("Column", "Photo", new { story = Model.Item1 })
        @if (Model.Item3)
        {//If user participates in this project
@*<a href="#" class="showLightBox_link mouseoverShow" rel="addPhotoBox">Добавить фото</a>*@
            @Html.ActionLink("Добавить фото", "UploadPhotos", "Photo", new { storyType = Model.Item1.GetType().FullName, id = Model.Item1.Id, returnUrl = Url.Action("View", "Project", new { id = Model.Item1.Id }) }, new { @class = "mouseoverShow" });
        }
    </div>
    <div id="project_leftCol_outer">
        <div id="project_leftCol">
		@if (!String.IsNullOrEmpty(Model.Item1.ShortDescription) || ViewBag.EditMode)
  {
            <div class="person" id="projectStarter">
                <a href="@Url.Action("View", "User", new { id = Model.Item1.Organizer.Id })">@Avatar.Medium(Model.Item1.Organizer, imageClass: "person_image person_image_large")</a>
                @Html.Partial("ProjectShortDescription", new Web.ViewModels.ProjectShortDescriptionModel(Model.Item1.Id, Model.Item1.ShortDescription, Model.Item1.Organizer.Id, Model.Item1.Organizer.DisplayName))
            </div>
	  }
            <div class="lightbox" id="userAppliedBox">
                <a href="#" class="lightbox_close">Закрыть</a>
                <div>
                    Спасибо, что решили нам помочь! Организатор проекта рассмотрит вашу кандидатуру.</div>
            </div>
            <a href="#" class="showLightBox_link" rel="userAppliedBox" id="thanksForApplying">
            </a>

            <script type="text/javascript" src="//yandex.st/share/share.js" charset="utf-8"></script>
            <div class="yashare-auto-init" data-yashareL10n="ru" data-yashareType="none" data-yashareQuickServices="vkontakte,facebook,twitter,lj"></div>

            <div id="project_participantList_container">
                <input type="hidden" name="vacancyIndex" value="-1" />
                <table id="project_participantList">
                    <thead>
                        <tr>
                            <th colspan="2" id="project_participantList_status_container">
                                @if (Model.Item1.IsCompleted)
                                {
                                <span class="project_participantList_status">Проект завершен. Записываться больше нельзя.</span>
                                <br/>
                                    @Html.ActionLink("Ближайшие проекты", "IndexUpcoming", "Project");
                                <br/>
                                <br/>    
                                <span class="project_participantList_status">Участие принимали:</span>
                                }
                                else
                                {
                                <span class="project_participantList_status">Нужны люди</span>
                                }
                            </th>
                            <th id="project_participantList_counter">
                                @if (Model.Item1.IsCompleted)
                                {
                                @:Всего @(ViewBag.WordFormatter.GetNumericalWordForm((string)"был", (int)Model.Item1.Participants.Count()))
                                }
                                else
                                {
                                @:Уже @(ViewBag.WordFormatter.GetNumericalWordForm((string)"записался", (int)Model.Item1.Participants.Count()))
                                }
                                <a href="#">@Model.Item1.Participants.Count() @(ViewBag.WordFormatter.GetNumericalWordForm((string)"человек", (int)Model.Item1.Participants.Count()))</a>:
                            </th>
                            <th>
                                &nbsp;
                            </th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach (var vacancyModel in Model.Item2)
                        {
                            @Html.Partial("VacancyDescription", Tuple.Create(vacancyModel, (Web.HelperClasses.Inflexion.IWordFormatter)ViewBag.WordFormatter));
                        }
                    </tbody>
                </table>
            </div>
            @if (!Model.Item1.IsCompleted)
            {
                //Project is not completed
            
                @Html.Partial("AddVacancy", null, new ViewDataDictionary() { { "ProjectId", Model.Item1.Id }, { "HasVacancies", Model.Item1.Vacancies.Count > 0 } });
                <br class="ownerOnly" />
                <br class="ownerOnly" />
            }
            <div class="ProjectDescription">
                <div id="person_textDescription_author">
                    @ProjectAvatar.Small(@Model.Item1, imageClass: "project_small_avatar avatarOnly", id: "project_forum_tradestart_userpic")
                    <div>
                        @if (/*Model.Item1.ProjectAvatar != null*/ true)
                        {
                            <a href="#" class="showLightBox_link avatarOnly mouseoverShow editButton editButton_delete"
                                rel="removeProjectAvatarBox"></a>
                        }
                        @using (Html.BeginForm("UpdateProjectAvatar", "Project", FormMethod.Post,
                    new { enctype = "multipart/form-data", id = "file_upload" }))
                        {
                            <fieldset>
                                @Html.Hidden("id", Model.Item1.Id)
                                <span class="file_upload_label mouseoverShow editButton_edit">&nbsp;</span>
                                <input type="file" name="projectAvatar" />
                            </fieldset>
                            <div id="uploadErrorMessage" class="errorMessage">
                            </div>
                        }
                        @*<a href="#" class="showLightBox_link mouseoverShow editButton_edit editButton avatarOnly" rel="editProjectAvatarBox">   Редактировать аватар проекта</a>*@
                    </div>
                </div>
                @Html.Partial("ProjectDescription", new Web.ViewModels.ProjectDescriptionModel(Model.Item1.Id, Model.Item1.Description))
            </div>
            <div class="both">
            </div>
            <br />
            <br />
            <div id="project_forum_container">
                <h2>
                    Обсуждение</h2>
                @Html.Action("Index", "Comment", new { story = Model.Item1 })
            </div>
        </div>
    </div>
</div>
<div id="lightbox_shadow">
    &nbsp;</div>
@*<div class="lightbox" id="editProjectAvatarBox">
    <a href="#" class="lightbox_close">Закрыть</a>
 @using (Html.BeginForm("UpdateProjectAvatar", "Project", FormMethod.Post, new { enctype = "multipart/form-data", id="file_upload" }))
 {
	<fieldset>
		@Html.Hidden("id", Model.Item1.Id)
	    <input type="button" class="file_upload_label" title="Выбрать аватар"/>
		@ProjectAvatar.Large(Model.Item1, imageClass: "project_image")
		<input type="file" name="projectAvatar"/>

		<br />
	</fieldset>
     <div id="uploadErrorMessage" class="errorMessage"></div>
	@Html.SubmitButton(null, "Сохранить")
 }
</div>*@
<script type="text/javascript">
    $(document).ready(function () {
        $('a[rel=fancybox_gallery1]').fancybox();
    });
</script>
<div id="lightbox_shadow">
    &nbsp;</div>
<div class="lightbox" id="removeProjectAvatarBox">
    <a href="#" class="lightbox_close">Закрыть</a>
    @using (Html.BeginForm("RemoveProjectAvatar", "Project", FormMethod.Post))
    {
        <fieldset>
            @Html.Hidden("id", Model.Item1.Id)
        </fieldset>
        <p>
            Вы уверены, что хотите удалить аватар проекта?</p>
	 
        @Html.SubmitButton(null, "Удалить")
    }
</div>
<div class="lightbox" id="removeVacancyBox">
    <a href="#" class="lightbox_close">Закрыть</a>
    @using (Html.BeginForm("Remove", "Vacancy", FormMethod.Post))
    {
        <fieldset>
            @Html.Hidden("vacancyId", "", new { id = "removeBoxVacancyId" })
        </fieldset>
        <p>
            Вы уверены, что хотите удалить вакансию '<span id="removeBoxVacancyName"></span>'?</p>
	 
        @Html.SubmitButton(null, "Удалить")
    }
</div>

<script type="text/javascript">
    $(document).ready(function () {
        $('#file_upload').fileUploadUI(
        'option',
        {
            onLoad: function (event, files, index, xhr, handler) {
                var json;
                if (xhr.responseText != undefined) {
                    json = $.parseJSON(xhr.responseText);
                } else {
                    // Instead of an XHR object, an iframe is used for legacy browsers:
                    json = $.parseJSON(xhr.contents().text());
                }
                if (json.code == 200) {
                    window.location.reload();
                } else {
                    $("#uploadErrorMessage").html(json.message);
                }
            },
            onError: function (event, files, index, xhr, handler) {
                // For JSON parsing errors, the load event is saved as handler.originalEvent:
                var json;
                if (handler.originalEvent) {
                    json = $.parseJSON(xhr.responseText);
                } else {
                    json = $.parseJSON(xhr.contents().text());
                }
            }
        }
    );
        jQuery.each($('.needApprovalForm'), function () {
            this.success = function () {
                $('#thanksForApplying').click();
            };
        });
    });
    $("#newVacancy_link").click(function () {
        $(this).hide();
        $("#newVacancy_container").slideToggle();
        $("#newVacanci_post").focus();
        return false;
    });

    $("#newVacancy_reset").click(function () {
        $("#newVacancy_container").slideToggle();
        $("#newVacancy_link").show();
        return false;
    });
</script>
